﻿Imports System.Data.OleDb
Public Class AddNewPlayer
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    End Sub

    Protected Sub bt_AddNewPlayer_Click(ByVal sender As Object, ByVal e As EventArgs) Handles bt_AddNewPlayer.Click


        Dim newfilename1 As String
        '' Dim newfilename2 As String
        '' Dim newfilename3 As String

        newfilename1 = Guid.NewGuid().ToString & getSuffix(f_picture1.FileName)
        If f_picture1.HasFile Then
            f_picture1.SaveAs(Server.MapPath("Pictures") & "/" & newfilename1)
        End If


        Dim conn As New OleDb.OleDbConnection(ConfigurationManager.ConnectionStrings("PlayersConnectionString").ConnectionString)
        Dim sql As String = "Insert into LawyersDetails (FirstName,LastName,DateOfBirth,Town,Practice,Telephone,Fax," & _
                                    "Email,Website,Address,CivilLitigationPersonalInjury,CompanyCommercial,Conveyancing,Crime,Employment,Family,WillsTrustsProbate,LawyerPicture, AddedDate) Values (@f1,@f2,@f3,@f4,@f5,@f6,@f7,@f8,@f9,@f10,@f11,@f12,@f13,@f14,@f15,@f16,@f17,@f18,Now())"
        Dim cmd As OleDbCommand = New OleDbCommand(sql, conn)
        cmd.CommandType = CommandType.Text

        cmd.Parameters.AddWithValue("@f1", tb_FName.Text)
        cmd.Parameters.AddWithValue("@f2", tb_LName.Text)
        cmd.Parameters.AddWithValue("@f3", DDL_Days.SelectedValue & "/" & DDL_Months.SelectedValue & "/" & DDL_Years.SelectedValue)
        cmd.Parameters.AddWithValue("@f4", tb_Town.Text)
        cmd.Parameters.AddWithValue("@f5", tb_Practice.Text)
        cmd.Parameters.AddWithValue("@f6", tb_Telephone.Text)
        cmd.Parameters.AddWithValue("@f7", tb_Fax.Text)
        cmd.Parameters.AddWithValue("@f8", tb_Email.Text)
        cmd.Parameters.AddWithValue("@f9", tb_Website.Text)
        ''cmd.Parameters.AddWithValue("@f10", tb_Telephone.Text)
        cmd.Parameters.AddWithValue("@f10", tb_Address.Text)
        cmd.Parameters.AddWithValue("@f11", tb_CivilLitigation.Text)
        cmd.Parameters.AddWithValue("@f12", tb_Commercial.Text)
        cmd.Parameters.AddWithValue("@f13", tb_Conveyancing.Text)
        cmd.Parameters.AddWithValue("@f14", tb_Crime.Text)
        cmd.Parameters.AddWithValue("@f15", tb_Employment.Text)
        cmd.Parameters.AddWithValue("@f16", tb_Family.Text)
        cmd.Parameters.AddWithValue("@f17", tb_Wills.Text)
        cmd.Parameters.AddWithValue("@f18", "Pictures/" & newfilename1)
        ''cmd.Parameters.AddWithValue("@f19", User.Identity.Name)

        conn.Open()
        cmd.ExecuteNonQuery()
        conn.Close()
        cmd.Dispose()
        conn.Dispose()
        Response.Redirect("Confirmation.aspx")
    End Sub

    Function getSuffix(ByVal fn As String)

        Dim fileparts = fn.Split(".")
        Dim suffix = fileparts(fileparts.Length - 1)
        Return "." & suffix

    End Function
End Class